package ltd.followkba.view;

import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.TextView;

import androidx.annotation.Nullable;
import androidx.constraintlayout.widget.ConstraintLayout;

import ltd.advskin.MSKIN;
import ltd.advskin.base.KcListener;
import ltd.advskin.view.KcBtnImage;
import ltd.advskin.view.KcBtnText;
import ltd.followkba.MAPP;
import ltd.followkba.R;
import ltd.followkba.task.BDbsAccount;

public class CloneView extends ConstraintLayout {
    public KcBtnImage kbiHeadUser;
    public TextView tvAppName;
    public TextView tvUserID;
    public TextView tvUserName;
    public TextView tvCloneAccount;
    public KcBtnText kbtSaveUser;
    public KcBtnText kbtSelectUser;

    private KcListener mKcListener;

    public CloneView(Context context) {
        super(context);
        initView(context);
    }
    public CloneView(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
        initView(context);
    }
    public CloneView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        initView(context);
    }

    public void initView(Context context){
        LayoutInflater.from(context).inflate(R.layout.view_clone, this, true);
        kbiHeadUser = findViewById(R.id.kbiHeadUser);
        tvAppName = findViewById(R.id.tvAppName);
        tvUserID = findViewById(R.id.tvUserID);
        tvUserName = findViewById(R.id.tvUserName);
        tvCloneAccount = findViewById(R.id.tvCloneAccount);
        kbtSaveUser = findViewById(R.id.kbtSaveUser);
        kbtSelectUser = findViewById(R.id.kbtSelectUser);
        kbiHeadUser.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (mKcListener != null){
                    mKcListener.onMessage(1);
                }
            }
        });
        kbtSaveUser.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (mKcListener != null){
                    mKcListener.onMessage(2);
                }
            }
        });
        kbtSelectUser.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (mKcListener != null){
                    mKcListener.onMessage(3);
                }
            }
        });
    }
    public void setListener(KcListener kcListener){
        mKcListener = kcListener;
    }

    public void setInfo(BDbsAccount bDbsAccount){
        String appName =  MAPP.mWorksName[bDbsAccount.CloneAppType];
        MSKIN.setText(appName, tvAppName);
        MSKIN.setText(String.format("ID:%s", bDbsAccount.CloneUserIdS), tvUserID);
        MSKIN.setText(bDbsAccount.CloneUserName, tvUserName);
        MAPP.showUserHead(bDbsAccount.CloneHead, kbiHeadUser);
    }

}


